subroutine alloc_event_table(p,n)
  use table_param,only:event_table
  use table_param,only:del_event_table
  use table_param,only:n_del_event_table
  use table_param,only:total_alloc_event_table
  use table_param,only:add_alloc_event_table
  use table_param,only:spont_event_table
  implicit none

  interface
     function reallocEventTable(p,nold,n)
       use derived,only:EventTable
       type(EventTable),pointer,dimension(:) :: &
            reallocEventTable,p
       integer,intent(in) :: nold,n
     end function reallocEventTable

     function reallocInt(p,n)
       integer,pointer,dimension(:) :: reallocInt,p
       integer,intent(in) :: n
     end function reallocInt
  end interface

  integer,intent(in) :: p
  integer,intent(out) :: n
  integer :: ne

  if (n_del_event_table.gt.0) then
     n=del_event_table(n_del_event_table)
     n_del_event_table=n_del_event_table-1
  else
     if (p.gt.total_alloc_event_table) then
        ne=total_alloc_event_table+&
             add_alloc_event_table
        event_table=>&
             reallocEventTable(event_table,&
             total_alloc_event_table,ne)
        del_event_table=>&
             reallocInt(del_event_table,ne)
        spont_event_table=>&
             reallocInt(spont_event_table,ne)
        total_alloc_event_table=ne
     end if
     n=p
  end if

  return

end subroutine alloc_event_table
